//
//  MainTabBarController.m
//  customer
//
//  Created by Holothurian on 2018/10/19.
//  Copyright © 2018年 yinlong. All rights reserved.
//

#import "MainTabBarController.h"
#import "BaseViewController.h"

@interface MainTabBarController ()

@end

@implementation MainTabBarController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createSubTabBarControllers];
}

- (void)createSubTabBarControllers{
    NSArray *defineArr = @[@[@"首页",@"Home"],@[@"我的订单",@"Repair"],@[@"个人中心",@"SelfCenter"]];
    //每个分视图控制器的名称 固定
    NSArray *viewControllerArray = @[@"HomeViewController",@"MyOrderBaseViewController",@"SelfCenterViewController"];
    //创建数组保存所有的子视图控制器
    NSMutableArray *viewControllers = [NSMutableArray array];
    for (NSInteger i = 0; i < defineArr.count; i++) {
        NSString *viewControllerName = viewControllerArray[i];
        //根据字符串获取类名
        Class viewControllerClass = NSClassFromString(viewControllerName);
        //创建视图控制器
        BaseViewController *baseViewCon = [[viewControllerClass alloc]init];
        
        //导航控制器base接入
        UINavigationController *navC = [[UINavigationController alloc]initWithRootViewController:baseViewCon];
        navC.view.tag = i;
        navC.navigationBar.hidden = NO;
        if (i != 2) {
            navC.navigationBar.barTintColor = [UIColor appColor];
        }else{
            navC.navigationBar.barTintColor = [HSPublic colorWithHexString:@"0082DF"];
        }
        

        //下端TabBar标题
        NSString *title = defineArr[i][0];
        //        //导航控制器标题
        //        baseViewCon.title = title;
        //图片名称
        NSString *imageName = [NSString stringWithFormat:@"tabBar_%@",defineArr[i][1]];
        //选中状态下的图片
        NSString *selectedImageName = [NSString stringWithFormat:@"tabBar_%@_H",defineArr[i][1]];
        //创建正常状态下的图片和选中图片对象
        UIImage *normalImage = [[UIImage imageNamed:imageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        UIImage *selectedImage = [[UIImage imageNamed:selectedImageName]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        //创建指定图片和标题的UITabBarItem
        UITabBarItem *item = [[UITabBarItem alloc]initWithTitle:title image:normalImage selectedImage:selectedImage];
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName:[HSPublic colorWithHexString:@"B5B4B4"] }forState:UIControlStateNormal ];
        [item setTitleTextAttributes:@{NSForegroundColorAttributeName:[HSPublic colorWithHexString:@"333333"] }forState:UIControlStateSelected];
        //设定item
        navC.tabBarItem = item;
        //视图控制器数组添加控制器
        [viewControllers addObject:navC];
        
    }
    
    [[UITabBarItem appearance]setTitlePositionAdjustment:UIOffsetMake(0, -3)];
    [[UITabBar appearance]setBackgroundColor:[UIColor whiteColor]];
//    //隐藏tabBar底部的一条线
//    [[UITabBar appearance] setShadowImage:[UIImage new]];
//    [[UITabBar appearance] setBackgroundImage:[[UIImage alloc]init]];
    
    //UITabBarController的视图控制器为设定的控制器
    self.viewControllers = viewControllers;
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
